<?php 
$langcode = $this->language->code;
$underscorepos = strpos($langcode, '_');

if($underscorepos !== false) {
	$langcode = substr($langcode, 0, $underscorepos);
}

$this->headScript()->offsetSetScript(1, 
	'var translationLanguage = "'.$this->escape($langcode).'"; '.
	'var toggleStateUrl = "'.$this->url(array('controller' => 'bundle', 'action' => 'togglestate', 'code' => $this->escape($this->language->code)),'default',true).'";'
);
$this->headScript()->appendFile($this->baseUrl('scripts/jquery.translate.js'));
?>

<h2>Bundle: <?php echo $this->escape($this->bundle->name) ?></h2>
<p>
	<?php echo $this->escape($this->bundle->description) ?> 
	<small>(Alias: <?php echo $this->escape($this->bundle->alias) ?></small>)
</p>

<div class="grid clearfix">
<div class="box_8 first">
<h3 style="margin-top: 0;">Language: <a href="<?php echo $this->url(array('controller' => 'language', 'action' => 'view', 'code' => $this->language->code),'default',true) ?>"
><?php echo $this->escape($this->language->name) ?></a></h3>
</div>
<div class="box_4 last" style="text-align: right;">

<?php if($this->excludetranslated): ?>
<a href="<?php echo $this->url(array('excludetranslated' => 0)) ?>" class="fancybutton emphasized">Show All Keys</a>
<?php else: ?>
<a href="<?php echo $this->url(array('excludetranslated' => 1)) ?>" class="fancybutton emphasized">Show Only Untranslated Keys</a>
<?php endif; ?>
</div>
</div>
<?php
for($pos = 0; $pos < count($this->keys); ++$pos):
	$key = $this->keys[$pos];
?>
<?php if($pos % 25 == 0): ?>
</table>
<?php if($pos != 0 ): ?>
<?php endif; ?>
<table cellpadding="0" cellspacing="0" style="width: 100%; margin-bottom: 2em;">
<thead>
	<tr>
		<th style="width: 20%;">Key</th>
		
		<?php if($this->language->original == 0): ?>
		<th style="width: 35%;">Original</th>
		<th style="width: 45%;">Translation</th>
		<th style="width: 24px;">&nbsp;</th>
		<?php else: ?>
		<th style="width: 80%;">Content</th>
		<?php endif; ?>
	</tr>
</thead>
<?php endif; ?>

<tbody>
	<tr class="<?php echo $key->translated == 1 ? 'translated' : 'untranslated' ?>" data-id="<?php echo $key->id ?>">
		<td><?php echo $this->escape($key->name); ?></td>
		<td class="original" id="o<?php echo $key->id ?>"><?php echo $this->escape($key->original); ?></td>
		
		<?php if($this->language->original == 0): ?>
		<td>
			<?php if(empty($key->translation)): ?>
			<em id="translation<?php echo $key->id?>" style="font-size: 0.9em;">no translation available</em>
			<?php else:?>
				<?php echo $this->escape($key->translation) ?>
			<?php endif; ?>
			
			<?php if($this->canedit): ?>
			<form id="edit<?php echo $key->id?>" action="<?php echo $this->url(array('key' => $key->id)) ?>" method="post" style="display:none">
			<textarea rows="2" name="translation[<?php echo $key->id ?>]" id="t<?php echo $key->id ?>"><?php echo $this->escape($key->translation) ?></textarea>
			<div style="text-align: right; margin-top: -0.5em;"><small class="autotranslate"><a href="#<?php echo $key->id ?>">Perform Automatic Translation</a> <span title="Powered by Google Translate" style="cursor:pointer;">*</span></small></div>
			
			<div style="margin-top: 0.5em; text-align: right;">
				<input type="submit" value="Save" class="fancybutton emphasized" />
			</div>
			</form>
			
			<div style="text-align: right; margin: 0.5em 0;">
				<a id="begin<?php echo $key->id?>" class="fancybutton begintranslate"
					data-fetchtranslation="<?php echo $this->url(array('action' => 'fetchtrans')) ?>"><?php echo empty($key->translation) ? 'Translate' : 'Change' ?></a>
			</div>
			<?php endif; ?>
		</td>
		<td class="state">&nbsp;</td>
		<?php endif; ?>
	</tr>
</tbody>

<?php endfor; ?>
</table>